import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import * as path from 'path'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({

  base: "./" ,      // 将html资源引用是的绝对路径，改为相对路径 ./ (便于electron等环境加载)

  resolve: {
      alias: {
        '@': path.resolve(__dirname, './src') ,
        '@beshell': path.resolve(__dirname, './src/@beshell') ,
      }
  } ,

  plugins: [
    vue() ,
    // AutoImport({
    //   resolvers: [ElementUiResolver()],
    // }),
    Components({
      resolvers: [NaiveUiResolver()],
    }),
  ] ,
  
  build: {
    minify: false,
    sourcemap: true, // 保留 source map
    assetsDir: '',
    rollupOptions: {
      output: {
        manualChunks: () => 'bundle', // 所有代码打包到一个 chunk
        entryFileNames: `bundle.js`,
        chunkFileNames: `bundle.js`,
        assetFileNames: `[name].[ext]`,
      },
      external: []
    },
    commonjsOptions: {
      sourceMap: true
    }
  },

  server: {
    cors: true ,
    hmr: {
      overlay: false
    }
  }
})
